package cms.manage.template.value.impl;

import cms.bean.template.Forum;
import cms.manage.template.impl.LikeTemplateManage;
import cms.manage.template.value.TplValueStrategy;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Map;

import static cms.common.SystemConstant.DisplayType.DISPLAY_COLLECTION;
import static cms.common.SystemConstant.DisplayType.DISPLAY_ENTITYBEAN;

@Service("点赞")
public class LikeStratey implements TplValueStrategy {
    @Resource
    LikeTemplateManage likeTemplateManage;//点赞 -- 模板方法实现

    @Override
    public Object doOperation(Forum forum, Map submitParameter, Map runtimeParameter) {
        if(forum.getForumChildType().equals("给话题点赞")){
            if(forum.getDisplayType().equals(DISPLAY_COLLECTION.getValue())){//集合
                Map<String,Object> value = likeTemplateManage.addLikeCollection(forum, submitParameter, runtimeParameter);
                return value;
            }
        }else if(forum.getForumChildType().equals("话题点赞总数")){
            if(forum.getDisplayType().equals(DISPLAY_ENTITYBEAN.getValue())){//实体对象
                Long value = likeTemplateManage.likeCountEntityBean(forum, submitParameter, runtimeParameter);
                return value;
            }
        }else if(forum.getForumChildType().equals("用户是否已经点赞该话题")){
            if(forum.getDisplayType().equals(DISPLAY_ENTITYBEAN.getValue())){//实体对象
                Boolean value = likeTemplateManage.alreadyLikedEntityBean(forum, submitParameter, runtimeParameter);
                return value;
            }
        }
        return null;
    }
}
